// import com.alibaba.druid.sql.dialect.oracle.ast.OracleSegmentAttributes;
// import com.alibaba.druid.sql.dialect.oracle.ast.OracleSegmentAttributesImpl;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

#include "SQLPartition.h"
#include "SQLName.h"
#include "SQLExpr.h"
#include "SQLSubPartition.h"
#include "SQLPartitionValue.h"
#include "../visitor/SQLASTVisitor.h"
#include "../../utils/listTran.h"

SQLPartition::SQLPartition()
{
  subPartitions = std::make_shared<std::list<SQLSubPartition_ptr>>();
}

SQLExpr_ptr SQLPartition::getLocality()
{
  return locality;
}

void SQLPartition::setLocality(SQLExpr_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(std::dynamic_pointer_cast<SQLObject>(SharedObject(SQLPartition)));
  }
  this->locality = x;
}

SQLName_ptr SQLPartition::getName()
{
  return name;
}

void SQLPartition::setName(SQLName_ptr name)
{
  if (name != nullptr)
  {
    name->setParent(std::dynamic_pointer_cast<SQLObject>(SharedObject(SQLPartition)));
  }
  this->name = name;
}

SQLExpr_ptr SQLPartition::getSubPartitionsCount()
{
  return subPartitionsCount;
}

void SQLPartition::setSubPartitionsCount(SQLExpr_ptr subPartitionsCount)
{
  if (subPartitionsCount != nullptr)
  {
    subPartitionsCount->setParent(std::dynamic_pointer_cast<SQLObject>(SharedObject(SQLPartition)));
  }
  this->subPartitionsCount = subPartitionsCount;
}

SQLPartitionValue_ptr SQLPartition::getValues()
{
  return values;
}

void SQLPartition::setValues(SQLPartitionValue_ptr values)
{
  if (values != nullptr)
  {
    values->SQLObjectImpl::setParent(std::dynamic_pointer_cast<SQLObject>(SharedObject(SQLPartition)));
  }
  this->values = values;
}

SQLSubPartition_list_ptr SQLPartition::getSubPartitions()
{
  return subPartitions;
}

void SQLPartition::addSubPartition(SQLSubPartition_ptr partition)
{
  if (partition != nullptr)
  {
    partition->SQLObjectImpl::setParent(std::dynamic_pointer_cast<SQLObject>(SharedObject(SQLPartition)));
  }
  this->subPartitions->push_back(partition);
}

SQLExpr_ptr SQLPartition::getIndexDirectory()
{
  return indexDirectory;
}

void SQLPartition::setIndexDirectory(SQLExpr_ptr indexDirectory)
{
  if (indexDirectory != nullptr)
  {
    indexDirectory->setParent(std::dynamic_pointer_cast<SQLObject>(SharedObject(SQLPartition)));
  }
  this->indexDirectory = indexDirectory;
}

SQLExpr_ptr SQLPartition::getDataDirectory()
{
  return dataDirectory;
}

void SQLPartition::setDataDirectory(SQLExpr_ptr dataDirectory)
{
  if (dataDirectory != nullptr)
  {
    dataDirectory->setParent(std::dynamic_pointer_cast<SQLObject>(SharedObject(SQLPartition)));
  }
  this->dataDirectory = dataDirectory;
}

SQLExpr_ptr SQLPartition::getMaxRows()
{
  return maxRows;
}

void SQLPartition::setMaxRows(SQLExpr_ptr maxRows)
{
  if (maxRows != nullptr)
  {
    maxRows->setParent(std::dynamic_pointer_cast<SQLObject>(SharedObject(SQLPartition)));
  }
  this->maxRows = maxRows;
}

SQLExpr_ptr SQLPartition::getMinRows()
{
  return minRows;
}

void SQLPartition::setMinRows(SQLExpr_ptr minRows)
{
  if (minRows != nullptr)
  {
    minRows->setParent(std::dynamic_pointer_cast<SQLObject>(SharedObject(SQLPartition)));
  }
  this->minRows = minRows;
}

SQLExpr_ptr SQLPartition::getEngine()
{
  return engine;
}

void SQLPartition::setEngine(SQLExpr_ptr engine)
{
  if (engine != nullptr)
  {
    engine->setParent(std::dynamic_pointer_cast<SQLObject>(SharedObject(SQLPartition)));
  }
  this->engine = engine;
}

SQLExpr_ptr SQLPartition::getComment()
{
  return comment;
}

void SQLPartition::setComment(SQLExpr_ptr comment)
{
  if (comment != nullptr)
  {
    comment->setParent(std::dynamic_pointer_cast<SQLObject>(SharedObject(SQLPartition)));
  }
  this->comment = comment;
}

void SQLPartition::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLPartition)))
  {
    acceptChild(visitor, name);
    acceptChild(visitor, std::dynamic_pointer_cast<SQLObject>(values));
    acceptChild(visitor, dataDirectory);
    acceptChild(visitor, indexDirectory);
    acceptChild(visitor, tablespace);
    acceptChild(visitor, maxRows);
    acceptChild(visitor, minRows);
    acceptChild(visitor, engine);
    acceptChild(visitor, comment);

    acceptChild(visitor, subPartitionsCount);
    acceptChild(visitor, storage);
    SQLObject_list_ptr tmp = ListTran::tran_class<SQLSubPartition, SQLObject>(subPartitions);
    acceptChild(visitor, tmp);
  }
  visitor->endVisit(SharedObject(SQLPartition));
}

SQLObject_ptr SQLPartition::getLobStorage()
{
  return lobStorage;
}

void SQLPartition::setLobStorage(SQLObject_ptr lobStorage)
{
  if (lobStorage != nullptr)
  {
    lobStorage->setParent(std::dynamic_pointer_cast<SQLObject>(SharedObject(SQLPartition)));
  }
  this->lobStorage = lobStorage;
}

BOOL_ptr SQLPartition::isSegmentCreationImmediate()
{
  return segmentCreationImmediate;
}

void SQLPartition::setSegmentCreationImmediate(BOOL_ptr segmentCreationImmediate)
{
  this->segmentCreationImmediate = segmentCreationImmediate;
}

BOOL_ptr SQLPartition::isSegmentCreationDeferred()
{
  return segmentCreationDeferred;
}

void SQLPartition::setSegmentCreationDeferred(BOOL_ptr segmentCreationDeferred)
{
  this->segmentCreationDeferred = segmentCreationDeferred;
}

SQLObject_ptr SQLPartition::clone()
{
  SQLObject_ptr clone_tmp = std::dynamic_pointer_cast<SQLObject>(SQLPartition_ptr(new SQLPartition()));
  SQLPartition_ptr x = std::dynamic_pointer_cast<SQLPartition>(clone_tmp);
  // SQLPartition *x = new SQLPartition();

  if (name != nullptr)
  {
    x->setName(std::dynamic_pointer_cast<SQLName>(name->clone()));
  }

  if (subPartitionsCount != nullptr)
  {
    x->setSubPartitionsCount(std::dynamic_pointer_cast<SQLExpr>(subPartitionsCount->clone()));
  }

  for (SQLSubPartition_ptr p : *subPartitions)
  {
    SQLSubPartition_ptr p2 = std::dynamic_pointer_cast<SQLSubPartition>(p->clone());
    p2->SQLObjectImpl::setParent(std::dynamic_pointer_cast<SQLObject>(x));
    x->subPartitions->push_back(p2);
  }

  if (values != nullptr)
  {
    x->setValues(std::dynamic_pointer_cast<SQLPartitionValue>(values->clone()));
  }

  if (dataDirectory != nullptr)
  {
    x->setDataDirectory(std::dynamic_pointer_cast<SQLExpr>(dataDirectory->clone()));
  }
  if (indexDirectory != nullptr)
  {
    x->setDataDirectory(std::dynamic_pointer_cast<SQLExpr>(indexDirectory->clone()));
  }
  if (maxRows != nullptr)
  {
    x->setDataDirectory(std::dynamic_pointer_cast<SQLExpr>(maxRows->clone()));
  }
  if (minRows != nullptr)
  {
    x->setDataDirectory(std::dynamic_pointer_cast<SQLExpr>(minRows->clone()));
  }
  if (engine != nullptr)
  {
    x->setDataDirectory(std::dynamic_pointer_cast<SQLExpr>(engine->clone()));
  }
  if (comment != nullptr)
  {
    x->setDataDirectory(std::dynamic_pointer_cast<SQLExpr>(comment->clone()));
  }
  x->segmentCreationImmediate = segmentCreationImmediate;
  x->segmentCreationDeferred = segmentCreationDeferred;

  if (lobStorage != nullptr)
  {
    x->setLobStorage(lobStorage->clone());
  }

  return std::dynamic_pointer_cast<SQLObject>(x);
}
